//静态数组array的应用
#include <iostream>
#include <array>
#include <fstream>
#include <cstring>
using namespace std;

int main(int argc, char const *argv[])
{
    fstream file("英雄名单.txt",ios::in);

    //静态数组
    array<string,200>heros;

    char name[50];
    for (int i = 0; i < heros.size() && !file.eof() ; i++)
    {
        file.getline(name,50);
        heros[i] = name;
    }

    //使用各种方式输出名单

    //1.传统方式
    cout << "英雄名单:" << endl;
    for(int i = 0; i < heros.size()&&!heros[i].empty(); i++)
    {
        cout << heros[i] << endl;
    }
    cout << endl;

    //2.枚举方式
    cout << "英雄名单:" << endl;
    for (string hero: heros)
    {
        if(hero.empty())
            break;
        cout << hero << endl;
    }
    cout << endl;

    //3.迭代器方式
    cout << "英雄名单:" << endl;
    for (array<string,200>::iterator it = heros.begin();it!=heros.end();it++)
    {
        if((*it).empty())
            break;
        cout << *it << endl;
    }
    cout << endl;

    return 0;

}
